import 'babel-polyfill'
import Vue from 'vue'
import 'vue-ydui/dist/ydui.flexible.js'
// import 'vue-ydui/dist/ydui.rem.css'
import 'css/base.scss'
import 'component'
import 'js/filters'
// import 'js/directives'
import router from './routes'
import store from './store'
import VueLazyload from 'vue-lazyload'
import YDUI from 'vue-ydui'

Vue.use(YDUI)
Vue.use(VueLazyload, {
  attempt: 1
})

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  if (to.meta.isAuth) {
    const token = store.getters.token
    if (token) {
      next()
    } else {
      window.$toast('亲，请先登录', () => {
        next(`/login?redirect=${encodeURIComponent(to.fullPath)}`)
      })
    }
  } else {
    next()
  }
})

export default new Vue({
  el: '#rootApp',
  router,
  store
})
